<template>
  <div class="login box">
    <div class="header">
      <img src="@/assets/images/login/bg1.png" class="bg1" alt />
      <!-- <img :src="joinUrlImg($route.meta.software_logo)" class="logo" alt /> -->
    </div>
    <div class="container">
      <div class="text">Hello</div>
      <!-- <div class="text_hi">欢迎使用{{ $route.meta.platform_name }}！</div> -->
      <div class="text_hi">欢迎使用心理云平台！</div>
      <div class="user">
        <!-- <div class="text">账号</div> -->
        <input type="text" placeholder="请输入账号" v-model="user" />
      </div>
      <div class="pwd">
        <!-- <div class="text">密码</div> -->
        <input type="password" placeholder="请输入密码" v-model="password" />
      </div>
      <!-- 忘记密码 -->
      <div class="forget" @click="$router.push(`forget/${$route.meta.id}`)">
        忘记密码？
      </div>

      <button class="login" @click="login">登录</button>
      <!-- 线条 -->
      <div class="line">
        <div class="line_bg"></div>
        <span>OR</span>
      </div>
      <button class="register" @click="register">账号注册</button>
    </div>

    <!-- <div class="updatePwd flex_column flex_center_jc flex_align_center">
      <input
        type="text"
        v-model="upadateUser"
        placeholder="请输入要更改的账号"
      />
      <input type="text" v-model="oldPwd" placeholder="请输入旧密码" />
      <input type="text" v-model="newPwd" placeholder="请输入新密码" />

      <button class="btn">确定</button>
    </div> -->
  </div>
</template>

<script>
import { login } from "@/api/login";
import { mapMutations } from "vuex";
import { joinUrlImg } from "@/utils/setUrlImg";
import aesCryptoJScopy from "@/utils/aesCryptoJScopy";
export default {
  data() {
    return {
      //账号
      user: "",
      //密码
      password: "",

      // 更改账号
      upadateUser: "",
      // 旧密码
      oldPwd: "",
      // 新密码
      newPwd: "",
    };
  },
  methods: {
    joinUrlImg,
    ...mapMutations(["SET_INFO"]),
    register() {
      this.$router.push("/register/" + this.$route.meta.id);
    },
    async login() {
      const params = {
        username: this.user,
        password: this.password,
      };
      const res = await login(params);
      if (res.code == 200) {
        // localStorage.setItem("loginPage", this.$route.path);
        sessionStorage.setItem("token", res.data.token);
        this.SET_INFO(res.data);
        this.$toast.success({ message: "登录成功！" });
        // this.$router.push('/nav/evaluate')
        this.$router.push("/nav/home");
      }
    },
    keyUpEnterLogin() {
      document.onkeyup = (event) => {
        if (event.keyCode == 13) {
          this.login();
        }
      };
    },
  },
  created() {},
  mounted() {
    this.keyUpEnterLogin();
  },
};
</script>

<style lang="less" scoped>
@import "./css/index.less";
</style>
